// 第六
$.ajax({
    type: "post",
    async: true, //异步执行
    url: "nydsj/yxj.html",
    dataType: "json", //返回数据形式为json
    success: function (json) {
        var myChart = echarts.init(document.getElementById('main6'));
// 指定图表的配置项和数据
        var option = {
            tooltip: { //提示框组件
                trigger: 'item', //触发类型(饼状图片就是用这个)
                formatter: "{a} <br/>{b} : {c} ({d}%)" //提示框浮层内容格式器
            }, legend: {
                orient: 'vertical',
                left: 'right',
                textStyle:{color:'#fff'},
                data: []
            },
            series: []
        };
        $.each(json, function (index, item) {
            option.legend.data.push(item.region);
            var show = false;
            var show1 = true;
            var label = {};
            var label1 = {};
            var labelLine = {};
            var position = 'center';
            var fontSize = '10';
            var fontWeight = 'bold';
            var textStyle = {};
            var a = '70';
            var b = '80';
            a = a - index * 20 + "%";
            b = b - index * 20 + "%";
            var radius = [a, b];
            textStyle.fontSize = fontSize;
            textStyle.fontWeight = fontWeight;
            label1.show = show1;
            label1.position = position;
            label1.textStyle = textStyle;
            var emphasis = {};
            label.show = show;
            labelLine.show = show1;
            var normal = {};
            normal.label = label;
            normal.labelLine = labelLine;
            var itemStyle = {};
            itemStyle.normal = normal;
            emphasis.label = label1;
            var newArray = {};
            var color = /*"#" + Math.floor(Math.random() * 16777216).toString(16)*/"#06195F";
            var color1 = "#" + Math.floor(Math.random() * 16777216).toString(16);
            var color2 = [color, color1];

            newArray.name = "数据";
            newArray.type = 'pie';
            newArray.center = ['50%', '50%'];
            newArray.radius = radius;
            newArray.color = color2;
            newArray.data = [];
            option.series.push(newArray);
        });
        $.each(json, function (index, item) {
            for (var j = 0; j < option.series.length; j++) {
                var dataa = {};
                var datas = {};

                if (item.region == option.legend.data[j]) {
                    dataa.value = item.potassium;
                    dataa.name = item.region;
                    datas.value = 100 - item.potassium;
                    datas.name = "";

                    option.series[j].data.push(dataa, datas);
                }
            }
        });


        myChart.setOption(option);
    },
    error: function (errorMsg) {
        alert("请求数据失败");
    }
});
